package com.groupbuying.pushordermsg.service.impl;

import com.groupbuying.pushordermsg.push.PushResult;
import com.groupbuying.pushordermsg.push.model.PushPayload;
import com.groupbuying.pushordermsg.service.PushMessageService;
import com.groupbuying.pushordermsg.util.PushUtils;
import com.groupbuying.pushordermsg.util.apiresult.ApiResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: wenguoqiang
 * @Email wguoqiango@163.com
 * @Date: 2019/12/19 0019 上午 10:49
 * @Des
 */
@Service
public class PushMessageServiceImpl implements PushMessageService {

    @Autowired
    private PushUtils pushUtils;

    @Override
    public ApiResult pushMessage(String storeUuid, String orderAmount) {

        if (StringUtils.isBlank(storeUuid) || StringUtils.isBlank(orderAmount)) {
            return ApiResult.failure(StringUtils.isBlank(storeUuid) ? "storeUuid" : "orderAmount" + "参数不为空");
        }
        //组装配置消息内容
        PushPayload payload = pushUtils.buildPushObject_all_alias_alert(storeUuid, orderAmount);
        //极光推送消息
        PushResult pushResult = pushUtils.JPushMsg(payload);
        if (pushResult == null ) {
            return ApiResult.failure("推送失败");
        }else if(pushResult.getResponseCode() != 200){
            return ApiResult.failure(pushResult.toString());
        }
        return ApiResult.success(pushResult.toString());
    }
}
